package controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import pojo.Carousel;
import service.CarouselService;

import java.util.List;

@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/carousel")
@Api(tags = "轮播图管理接口", description = "提供轮播图相关的增删改查功能")
public class CarouselController {

    @Autowired
    private CarouselService carouselService;

    @GetMapping("/findAll")
    @ResponseBody
    @ApiOperation(value = "查询所有轮播图", notes = "获取系统中所有轮播图的信息")
    public List<Carousel> findAll() {
        return carouselService.findAll();
    }

    @GetMapping("/findById")
    @ResponseBody
    @ApiOperation(value = "根据ID查询轮播图", notes = "通过轮播图ID获取具体轮播图信息")
    @ApiImplicitParam(name = "id", value = "轮播图ID", required = true, dataType = "Integer", paramType = "query")
    public Carousel findById(@RequestParam Integer id) {
        return carouselService.findById(id);
    }

    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加轮播图", notes = "新增轮播图信息到系统")
    public int add(@RequestBody Carousel carousel) {
        return carouselService.add(carousel);
    }

    @PostMapping("/update")
    @ResponseBody
    @ApiOperation(value = "更新轮播图信息", notes = "根据轮播图ID更新其信息")
    public int update(@RequestBody Carousel carousel) {
        return carouselService.update(carousel);
    }

    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "删除轮播图", notes = "根据轮播图ID删除该轮播图信息")
    @ApiImplicitParam(name = "id", value = "轮播图ID", required = true, dataType = "Integer", paramType = "query")
    public int delete(@RequestParam Integer id) {
        return carouselService.deleteCarousel(id);
    }
}